"""
@author: xxw
@file: 05.多进程-multiprocessing.py
@time: 2023/6/27 14:34
"""
# from multiprocessing import Process, current_process
# import time

# ls = []
#
# def task(i):
#     print(current_process().name, f"start......{i}")
#     time.sleep(2)
#     ls.append(i)
#     print(f"lst is {ls}")
#     print(current_process().name, f"end.....{i}")
# # 各个进程都拥有一份数据，相互隔离
#
#
# # 直接运行才能进行多进程操作，不然会报错
# if __name__ == "__main__":
#     for i in range(4):
#         p = Process(target=task, args=(i,))
#         p.start()

# 自定义进程类
import multiprocessing
class MyProcess(multiprocessing.Process):
    def __init__(self, num):
        super().__init__()
        self.num = num

    def run(self):
        print(f"running...{self.num}")

p1 = MyProcess(1)
p2 = MyProcess(2)
if __name__ == "__main__":
    p1.start()
    p2.start()


